/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Valuador2.java
 *
 * Created on 28-oct-2009, 8:48:29
 */

package scapi.gui;

import java.awt.Component;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.sql.SQLException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import scapi.entidades.CatalogoProducto;
import scapi.entidades.Joya;
import scapi.entidades.Prenda;
import scapi.servidor.servidores.ServidorACatalogoProd;
import scapi.servidor.servidores.ServidorCola;
import scapi.utilerias.EValidacion;
import scapi.utilerias.ExcepcionValidacion;
import scapi.utilerias.ServidorFactory;

/**
 *
 * @author Sideroz Inc.
 */
public class Valuador2 extends javax.swing.JFrame {
    private ServidorACatalogoProd servACProducto;
    private ServidorCola servCola;
    

    /** Creates new form Valuador2 */
    public Valuador2() {
        initComponents();
        try{
           
          //  servAEmpenio = (ServidorAEmpenio) Naming.lookup("servEmpenio");
            servACProducto =  (ServidorACatalogoProd) ServidorFactory.obtenerServidor(ServidorFactory.ServidorCatalogoProducto);
            servCola =  (ServidorCola) ServidorFactory.obtenerServidor(ServidorFactory.ServidorCola);

            CatalogoProducto[] catalogo = servACProducto.consultaCatalogoProducto();
            System.out.println("La longitud de catalogo "+catalogo.length);
            CBVcategoria.setModel(new DefaultComboBoxModel(catalogo));


        }catch(RemoteException e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "Imposible conectar a servidor", "ERROR", JOptionPane.ERROR_MESSAGE);
        }catch(NotBoundException e){
            e.printStackTrace();

        }catch(SQLException e){
            e.printStackTrace();

        }catch(MalformedURLException e){
            e.printStackTrace();
        }

   

        pack();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btgMaterial = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        JLVnom_pro = new javax.swing.JLabel();
        JLVdesc_pro = new javax.swing.JLabel();
        SPVdescripcion = new javax.swing.JScrollPane();
        TAVdescripcion = new javax.swing.JTextArea();
        JLVcategoria = new javax.swing.JLabel();
        CBVcategoria = new javax.swing.JComboBox();
        TFVnom_pro = new javax.swing.JTextField();
        JPVjoyas = new javax.swing.JPanel();
        JLVmaterial = new javax.swing.JLabel();
        TFVmaterial = new javax.swing.JTextField();
        CBVplata = new javax.swing.JCheckBox();
        CBVdiamante = new javax.swing.JCheckBox();
        CBVotros = new javax.swing.JCheckBox();
        CBVoro = new javax.swing.JCheckBox();
        JLVpeso = new javax.swing.JLabel();
        TFVpeso = new javax.swing.JTextField();
        JLVpureza = new javax.swing.JLabel();
        TFVpureza = new javax.swing.JTextField();
        JPVmarcamodelo = new javax.swing.JPanel();
        TFVmodelo = new javax.swing.JTextField();
        TFVmarca = new javax.swing.JTextField();
        JLVmarca = new javax.swing.JLabel();
        JLVmodelo = new javax.swing.JLabel();
        TFVavaluo = new javax.swing.JTextField();
        JLVavaluo = new javax.swing.JLabel();
        CBVpresentacion = new javax.swing.JComboBox();
        JLVpres_pro = new javax.swing.JLabel();
        TFVprestamo = new javax.swing.JTextField();
        CBVcambiarPrestamo = new javax.swing.JCheckBox();
        JLVprestamo = new javax.swing.JLabel();
        JBVcancelar = new javax.swing.JButton();
        JBVaceptar = new javax.swing.JButton();
        JBVimprimir = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        JMarchivo = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        JMedicion = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Avaluo");
        setLocationByPlatform(true);
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        JLVnom_pro.setText("Producto");

        JLVdesc_pro.setText("Descripcion");

        TAVdescripcion.setColumns(20);
        TAVdescripcion.setLineWrap(true);
        TAVdescripcion.setRows(5);
        SPVdescripcion.setViewportView(TAVdescripcion);

        JLVcategoria.setText("Categoria");

        CBVcategoria.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                CBVcategoriaItemStateChanged(evt);
            }
        });

        JPVjoyas.setEnabled(false);

        JLVmaterial.setText("Material(es)");
        JLVmaterial.setEnabled(false);

        TFVmaterial.setEnabled(false);

        CBVplata.setText("Plata");
        CBVplata.setEnabled(false);

        CBVdiamante.setText("Diamante");
        CBVdiamante.setEnabled(false);

        CBVotros.setText("Otros");
        CBVotros.setEnabled(false);
        CBVotros.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBVotrosActionPerformed(evt);
            }
        });

        CBVoro.setText("Oro");
        CBVoro.setEnabled(false);

        JLVpeso.setText("Peso");
        JLVpeso.setEnabled(false);

        TFVpeso.setEnabled(false);

        JLVpureza.setText("Pureza");
        JLVpureza.setEnabled(false);

        TFVpureza.setEnabled(false);

        javax.swing.GroupLayout JPVjoyasLayout = new javax.swing.GroupLayout(JPVjoyas);
        JPVjoyas.setLayout(JPVjoyasLayout);
        JPVjoyasLayout.setHorizontalGroup(
            JPVjoyasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPVjoyasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JPVjoyasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JPVjoyasLayout.createSequentialGroup()
                        .addGroup(JPVjoyasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JLVmaterial)
                            .addComponent(CBVotros))
                        .addGap(21, 21, 21)
                        .addGroup(JPVjoyasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(JPVjoyasLayout.createSequentialGroup()
                                .addComponent(CBVoro)
                                .addGap(18, 18, 18)
                                .addComponent(CBVplata)
                                .addGap(18, 18, 18)
                                .addComponent(CBVdiamante, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(TFVmaterial, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)))
                    .addGroup(JPVjoyasLayout.createSequentialGroup()
                        .addComponent(JLVpeso)
                        .addGap(18, 18, 18)
                        .addComponent(TFVpeso, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(JLVpureza)
                        .addGap(18, 18, 18)
                        .addComponent(TFVpureza, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)))
                .addContainerGap())
        );
        JPVjoyasLayout.setVerticalGroup(
            JPVjoyasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPVjoyasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JPVjoyasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLVmaterial)
                    .addComponent(CBVoro)
                    .addComponent(CBVplata)
                    .addComponent(CBVdiamante))
                .addGap(7, 7, 7)
                .addGroup(JPVjoyasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CBVotros)
                    .addComponent(TFVmaterial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(JPVjoyasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLVpeso)
                    .addComponent(TFVpureza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TFVpeso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLVpureza))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        JPVmarcamodelo.setEnabled(false);

        TFVmodelo.setEnabled(false);

        TFVmarca.setEnabled(false);
        TFVmarca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TFVmarcaActionPerformed(evt);
            }
        });

        JLVmarca.setText("Marca");
        JLVmarca.setEnabled(false);

        JLVmodelo.setText("Modelo");
        JLVmodelo.setEnabled(false);

        javax.swing.GroupLayout JPVmarcamodeloLayout = new javax.swing.GroupLayout(JPVmarcamodelo);
        JPVmarcamodelo.setLayout(JPVmarcamodeloLayout);
        JPVmarcamodeloLayout.setHorizontalGroup(
            JPVmarcamodeloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPVmarcamodeloLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JPVmarcamodeloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JLVmodelo)
                    .addComponent(JLVmarca))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPVmarcamodeloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TFVmodelo, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
                    .addComponent(TFVmarca, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE))
                .addContainerGap())
        );
        JPVmarcamodeloLayout.setVerticalGroup(
            JPVmarcamodeloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPVmarcamodeloLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JPVmarcamodeloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLVmarca)
                    .addComponent(TFVmarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(JPVmarcamodeloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLVmodelo)
                    .addComponent(TFVmodelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        TFVavaluo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                TFVavaluoFocusLost(evt);
            }
        });

        JLVavaluo.setText("Avaluo");

        CBVpresentacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Muy buena", "Buena", "Regular", "Mala", "Muy mala" }));
        CBVpresentacion.setSelectedIndex(1);
        CBVpresentacion.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                CBVpresentacionItemStateChanged(evt);
            }
        });

        JLVpres_pro.setText("Presentacion");

        TFVprestamo.setEditable(false);

        CBVcambiarPrestamo.setText("Cambiar");
        CBVcambiarPrestamo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBVcambiarPrestamoActionPerformed(evt);
            }
        });

        JLVprestamo.setText("Prestamo");

        JBVcancelar.setText("Cancelar");
        JBVcancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBVcancelarActionPerformed(evt);
            }
        });

        JBVaceptar.setText("Aceptar");
        JBVaceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBVaceptarActionPerformed(evt);
            }
        });

        JBVimprimir.setText("Imprimir");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(JBVimprimir)
                        .addGap(18, 18, 18)
                        .addComponent(JBVaceptar)
                        .addGap(18, 18, 18)
                        .addComponent(JBVcancelar))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(JLVnom_pro)
                                .addComponent(JLVdesc_pro))
                            .addGap(23, 23, 23)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(TFVnom_pro, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                                .addComponent(SPVdescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(JLVcategoria)
                            .addGap(31, 31, 31)
                            .addComponent(CBVcategoria, 0, 249, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(JLVavaluo)
                                .addComponent(JLVpres_pro)
                                .addComponent(JLVprestamo))
                            .addGap(16, 16, 16)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(CBVpresentacion, 0, 297, Short.MAX_VALUE)
                                .addComponent(TFVavaluo)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                    .addComponent(TFVprestamo, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                                    .addGap(18, 18, 18)
                                    .addComponent(CBVcambiarPrestamo, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(JPVmarcamodelo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(JPVjoyas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLVnom_pro)
                    .addComponent(TFVnom_pro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JLVdesc_pro)
                    .addComponent(SPVdescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLVcategoria)
                    .addComponent(CBVcategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JPVjoyas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JPVmarcamodelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFVavaluo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLVavaluo))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CBVpresentacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLVpres_pro))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFVprestamo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CBVcambiarPrestamo)
                    .addComponent(JLVprestamo))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JBVcancelar)
                    .addComponent(JBVaceptar)
                    .addComponent(JBVimprimir))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        JMarchivo.setText("Archivo");

        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/scapi/imagenes/exit.png"))); // NOI18N
        jMenuItem1.setText("Salir");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        JMarchivo.add(jMenuItem1);

        jMenuBar1.add(JMarchivo);

        JMedicion.setText("Ayuda");

        jMenuItem2.setText("About");
        JMedicion.add(jMenuItem2);

        jMenuBar1.add(JMedicion);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JBVaceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBVaceptarActionPerformed

        try {
            String nombre = EValidacion.campoVacio(TFVnom_pro.getText(),"Nombre producto");
            String desc = EValidacion.vacio(TAVdescripcion.getText(), "Descripcion");
            String material = "";
            String marca = "";
            String modelo = "";
            float peso = 0;
            int pureza = 0;
            float prestamo =0;
            switch(CBVcategoria.getSelectedIndex()) {
                case 0:
                    throw new ExcepcionValidacion("Debe elegir una opcion de categoria");
                case 1:
                    if (!CBVoro.isSelected() && !CBVplata.isSelected() && !CBVdiamante.isSelected() && !CBVotros.isSelected())
                        throw new ExcepcionValidacion("Debe elegir un material");
                    else {
                        if (CBVoro.isSelected())
                            if (material.isEmpty())
                                material += CBVoro.getText();
                            else
                                material += ", " + CBVoro.getText();
                        if (CBVplata.isSelected())
                            if (material.isEmpty())
                                material += CBVplata.getText();
                            else
                                material += ", " + CBVplata.getText();
                        if (CBVdiamante.isSelected())
                            if (material.isEmpty())
                                material += CBVdiamante.getText();
                            else
                                material += ", " + CBVdiamante.getText();
                        if (CBVotros.isSelected())
                            if (material.isEmpty())
                                material += EValidacion.vacio(TFVmaterial.getText(), "Material");
                            else
                                material += ", " + EValidacion.vacio(TFVmaterial.getText(), "Material");
                    }
                    System.out.println(material);
                    peso = EValidacion.flotante(TFVpeso.getText(), "peso");
                    pureza = EValidacion.entero(TFVpureza.getText(), "pureza");
                    break;
                default:
                    marca = EValidacion.campoVacio(TFVmarca.getText(), "Marca");
                    modelo = EValidacion.campoVacio(TFVmodelo.getText(), "Modelo");
                    break;
            }
            
            float avaluo = EValidacion.flotante(TFVavaluo.getText(), "Avaluo");
            if (CBVcambiarPrestamo.isSelected())
                prestamo = EValidacion.flotante(TFVprestamo.getText(), "Prestamo");
            else{

                prestamo = EValidacion.flotante(TFVprestamo.getText(), "Prestamo");

                if(prestamo > avaluo)
                    throw new ExcepcionValidacion("El prestamo no puede ser mayor que el avaluo");
            }

            CatalogoProducto categoria = (CatalogoProducto) CBVcategoria.getSelectedItem();
            String presentacion = (String) CBVpresentacion.getSelectedItem();



            if(categoria.getNomCProducto().equalsIgnoreCase("joyeria")){

                Joya joya = new Joya(0,nombre, desc,presentacion, "activo", categoria.getIdCProducto(), avaluo,material,peso,pureza );
                servCola.addColaRegistrador(1, joya);
                limpiarForm();
                JOptionPane.showMessageDialog(this, "Alta Exitosa","Alta",JOptionPane.INFORMATION_MESSAGE);


            }else{
                Prenda prenda = new Prenda(0, nombre, desc, presentacion, "activo", categoria.getIdCProducto(), avaluo, marca, modelo);
                servCola.addColaRegistrador(1, prenda);

                limpiarForm();
                JOptionPane.showMessageDialog(this, "Alta Exitosa","Alta",JOptionPane.INFORMATION_MESSAGE);
            }


        } catch (ExcepcionValidacion e) {

            JOptionPane.showMessageDialog(this, e.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);

        } catch(RemoteException e){
            e.printStackTrace();
        }






    }//GEN-LAST:event_JBVaceptarActionPerformed

    private void JBVcancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBVcancelarActionPerformed
        // TODO add your handling code here:
        System.exit(0);
}//GEN-LAST:event_JBVcancelarActionPerformed

    private void CBVcambiarPrestamoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBVcambiarPrestamoActionPerformed
        if (CBVcambiarPrestamo.isSelected())
            TFVprestamo.setEditable(true);
        else
            TFVprestamo.setEditable(false);
}//GEN-LAST:event_CBVcambiarPrestamoActionPerformed

    private void CBVpresentacionItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_CBVpresentacionItemStateChanged
        // TODO add your handling code here:
        System.out.println(CBVpresentacion.getSelectedIndex());
        switch (CBVpresentacion.getSelectedIndex()) {
            case 0:
                try {
                    float pres = (float) (0.85 * EValidacion.flotante(TFVavaluo.getText(), "Avaluo"));
                    TFVprestamo.setText("" + pres);
                } catch (ExcepcionValidacion e){
                    System.out.println(e.getMessage());
                }
                break;
            case 1:
                try {
                    float pres = (float) (0.75 * EValidacion.flotante(TFVavaluo.getText(), "Avaluo"));
                    TFVprestamo.setText("" + pres);
                } catch (ExcepcionValidacion e){
                    System.out.println(e.getMessage());
                }
                break;
            case 2:
                try {
                    float pres = (float) (0.65 * EValidacion.flotante(TFVavaluo.getText(), "Avaluo"));
                    TFVprestamo.setText("" + pres);
                } catch (ExcepcionValidacion e){
                    System.out.println(e.getMessage());
                }
                break;
            case 3:
                try {
                    float pres = (float) (0.55 * EValidacion.flotante(TFVavaluo.getText(), "Avaluo"));
                    TFVprestamo.setText("" + pres);
                } catch (ExcepcionValidacion e){
                    System.out.println(e.getMessage());
                }
                break;
            case 4:
                try {
                    float pres = (float) (0.45 * EValidacion.flotante(TFVavaluo.getText(), "Avaluo"));
                    TFVprestamo.setText("" + pres);
                } catch (ExcepcionValidacion e){
                    System.out.println(e.getMessage());
                }
                break;
            default:
                break;

        }
}//GEN-LAST:event_CBVpresentacionItemStateChanged

    private void TFVavaluoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_TFVavaluoFocusLost
        // TODO add your handling code here:
        CBVpresentacionItemStateChanged(null);
}//GEN-LAST:event_TFVavaluoFocusLost

    private void TFVmarcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TFVmarcaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_TFVmarcaActionPerformed

    private void CBVotrosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBVotrosActionPerformed
        // TODO add your handling code here:
        System.out.println(evt.getActionCommand());
        if (CBVotros.isSelected())
            TFVmaterial.setEnabled(true);
        else
            TFVmaterial.setEnabled(false);
}//GEN-LAST:event_CBVotrosActionPerformed

    private void CBVcategoriaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_CBVcategoriaItemStateChanged
        // TODO add your handling code here:
        if (CBVcategoria.getSelectedIndex() != 0){
            if (CBVcategoria.getSelectedIndex() == 1) {
                //Activar panel de joyas
                JPVjoyas.setEnabled(true);
                JLVmaterial.setEnabled(true);
                CBVoro.setEnabled(true);
                CBVplata.setEnabled(true);
                CBVdiamante.setEnabled(true);
                CBVotros.setEnabled(true);
                JLVpeso.setEnabled(true);
                TFVpeso.setEnabled(true);
                JLVpureza.setEnabled(true);
                TFVpureza.setEnabled(true);
                if (CBVotros.isSelected())
                    TFVmaterial.setEnabled(true);
                //Desactivar panel de prenda
                JPVmarcamodelo.setEnabled(false);
                JLVmarca.setEnabled(false);
                TFVmarca.setEnabled(false);
                JLVmodelo.setEnabled(false);
                TFVmodelo.setEnabled(false);
            } else {
                //Activar panel de prenda
                JPVmarcamodelo.setEnabled(true);
                JLVmarca.setEnabled(true);
                TFVmarca.setEnabled(true);
                JLVmodelo.setEnabled(true);
                TFVmodelo.setEnabled(true);
                //Desactivar panel de joyas
                JPVjoyas.setEnabled(false);
                JLVmaterial.setEnabled(false);
                CBVoro.setEnabled(false);
                CBVplata.setEnabled(false);
                CBVdiamante.setEnabled(false);
                CBVotros.setEnabled(false);
                TFVmaterial.setEnabled(false);
                JLVpeso.setEnabled(false);
                TFVpeso.setEnabled(false);
                JLVpureza.setEnabled(false);
                TFVpureza.setEnabled(false);
            }
        } else {
            //Desactivar panel de joyas
            JPVjoyas.setEnabled(false);
            JLVmaterial.setEnabled(false);
            CBVoro.setEnabled(false);
            CBVplata.setEnabled(false);
            CBVdiamante.setEnabled(false);
            CBVotros.setEnabled(false);
            TFVmaterial.setEnabled(false);
            JLVpeso.setEnabled(false);
            TFVpeso.setEnabled(false);
            JLVpureza.setEnabled(false);
            TFVpureza.setEnabled(false);
            //Desactivar panel de prenda
            JPVmarcamodelo.setEnabled(false);
            JLVmarca.setEnabled(false);
            TFVmarca.setEnabled(false);
            JLVmodelo.setEnabled(false);
            TFVmodelo.setEnabled(false);
        }
}//GEN-LAST:event_CBVcategoriaItemStateChanged

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed

        System.exit(0);
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1ActionPerformed


    private void limpiarPanel(JPanel panel){
        Component[] comp = panel.getComponents();
        for (int i = 0; i < comp.length; i++) {
            Component component = comp[i];
            if(component instanceof JTextField){
                JTextField componente = (JTextField) component;
                componente.setText("");
            }else if(component instanceof JComboBox){
                JComboBox comp2 = (JComboBox) component;
                comp2.setSelectedIndex(0);

            }else if(component instanceof JCheckBox){
                JCheckBox box = (JCheckBox) component;
                box.setSelected(false);
            }

        }

    }

    private void limpiarForm(){
        limpiarPanel(jPanel1);
        limpiarPanel(JPVjoyas);
        limpiarPanel(JPVmarcamodelo);
        TAVdescripcion.setText("");

    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
	/*try
	        {
	           UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
	        }
	        catch (Exception e) {
	            e.printStackTrace();
	        }
*/
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Valuador2().setVisible(true);
            }
        });
    }

        public static void iniciar() {


        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Valuador2().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox CBVcambiarPrestamo;
    private javax.swing.JComboBox CBVcategoria;
    private javax.swing.JCheckBox CBVdiamante;
    private javax.swing.JCheckBox CBVoro;
    private javax.swing.JCheckBox CBVotros;
    private javax.swing.JCheckBox CBVplata;
    private javax.swing.JComboBox CBVpresentacion;
    private javax.swing.JButton JBVaceptar;
    private javax.swing.JButton JBVcancelar;
    private javax.swing.JButton JBVimprimir;
    private javax.swing.JLabel JLVavaluo;
    private javax.swing.JLabel JLVcategoria;
    private javax.swing.JLabel JLVdesc_pro;
    private javax.swing.JLabel JLVmarca;
    private javax.swing.JLabel JLVmaterial;
    private javax.swing.JLabel JLVmodelo;
    private javax.swing.JLabel JLVnom_pro;
    private javax.swing.JLabel JLVpeso;
    private javax.swing.JLabel JLVpres_pro;
    private javax.swing.JLabel JLVprestamo;
    private javax.swing.JLabel JLVpureza;
    private javax.swing.JMenu JMarchivo;
    private javax.swing.JMenu JMedicion;
    private javax.swing.JPanel JPVjoyas;
    private javax.swing.JPanel JPVmarcamodelo;
    private javax.swing.JScrollPane SPVdescripcion;
    private javax.swing.JTextArea TAVdescripcion;
    private javax.swing.JTextField TFVavaluo;
    private javax.swing.JTextField TFVmarca;
    private javax.swing.JTextField TFVmaterial;
    private javax.swing.JTextField TFVmodelo;
    private javax.swing.JTextField TFVnom_pro;
    private javax.swing.JTextField TFVpeso;
    private javax.swing.JTextField TFVprestamo;
    private javax.swing.JTextField TFVpureza;
    private javax.swing.ButtonGroup btgMaterial;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables

}
